package cn.com.ghy.android.bean;

import java.io.InputStream;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlSerializer;
import cn.com.ghy.android.util.XMLStatic;

import android.util.Xml;

/**
 * @软件著作权:金红叶纸业集团有限公司
 * @系统名称:SFA系统
 * @Description:今天协访大店信息解析器
 * @author wuz  @date 2011-6-21 16:49:25
 * @版本历史:v1.0
 * @Copyright:Copyright (c) 2011-2012 
 */

public class CoopVisitBigShopInfoBeanParser {
	
	public static String createVsPartDataXMLForBigShop(String vstype, CoopVisitBigShopInfoBean bean,
			Writer writer) throws Exception {
        XmlSerializer xmlSerializer = Xml.newSerializer();
        
        xmlSerializer.setOutput(writer);
        xmlSerializer.startDocument("UTF-8", true);
        xmlSerializer.startTag("", XMLStatic.CONTENT);
        xmlSerializer.attribute("", XMLStatic.TOTAL_RECORD, "1");
        xmlSerializer.startTag("", XMLStatic.RECORDS);
        
        xmlSerializer.startTag("", XMLStatic.VSTYPE);
        xmlSerializer.text(vstype);
		xmlSerializer.endTag("", XMLStatic.VSTYPE);
		
        xmlSerializer.startTag("", XMLStatic.PARTNER);
        xmlSerializer.text(bean.getPartner());
		xmlSerializer.endTag("", XMLStatic.PARTNER);
		xmlSerializer.startTag("", XMLStatic.VSDATE);
        xmlSerializer.text(bean.getVsdate());
        xmlSerializer.endTag("", XMLStatic.VSDATE);
    	xmlSerializer.startTag("", XMLStatic.CONTENT);
        xmlSerializer.text(bean.getContent());
		xmlSerializer.endTag("", XMLStatic.CONTENT);
		xmlSerializer.startTag("", XMLStatic.AVGMONTHSALE);
        xmlSerializer.text(bean.getAvgmonthsale());
		xmlSerializer.endTag("", XMLStatic.AVGMONTHSALE);
		xmlSerializer.startTag("", XMLStatic.PREMONTHSALE);
        xmlSerializer.text(bean.getPremonthsale());
		xmlSerializer.endTag("", XMLStatic.PREMONTHSALE);
		xmlSerializer.startTag("", XMLStatic.FIRSTCMPTSALE);
        xmlSerializer.text(bean.getFirstcmptsale());
		xmlSerializer.endTag("", XMLStatic.FIRSTCMPTSALE);
		xmlSerializer.startTag("", XMLStatic.PJPVISIT);
        xmlSerializer.text(bean.getPjpvisit());
		xmlSerializer.endTag("", XMLStatic.PJPVISIT);
		xmlSerializer.startTag("", XMLStatic.PREPARE);
        xmlSerializer.text(bean.getPrepare());
		xmlSerializer.endTag("", XMLStatic.PREPARE);
		xmlSerializer.startTag("", XMLStatic.TALKLEVEL);
        xmlSerializer.text(null == bean.getTalklevel() ? "" : bean.getTalklevel());
		xmlSerializer.endTag("", XMLStatic.TALKLEVEL);
		xmlSerializer.startTag("", XMLStatic.HANDLEVEL);
        xmlSerializer.text(null == bean.getHandlevel() ? "" : bean.getHandlevel());
		xmlSerializer.endTag("", XMLStatic.HANDLEVEL);
		xmlSerializer.startTag("", XMLStatic.SHELFALL);
        xmlSerializer.text(bean.getShelfall());
		xmlSerializer.endTag("", XMLStatic.SHELFALL);
		xmlSerializer.startTag("", XMLStatic.SHELFSUB);
        xmlSerializer.text(bean.getShelfsub());
		xmlSerializer.endTag("", XMLStatic.SHELFSUB);
		xmlSerializer.startTag("", XMLStatic.SHELFLEVEL);
        xmlSerializer.text(null == bean.getShelflevel() ? "" : bean.getShelflevel());
		xmlSerializer.endTag("", XMLStatic.SHELFLEVEL);
		xmlSerializer.startTag("", XMLStatic.ISVISIT);
        xmlSerializer.text("");
		xmlSerializer.endTag("", XMLStatic.ISVISIT);
		xmlSerializer.startTag("", XMLStatic.CMULEVEL);
        xmlSerializer.text(null == bean.getCmulevel() ? "" : bean.getCmulevel());
		xmlSerializer.endTag("", XMLStatic.CMULEVEL);
		xmlSerializer.startTag("", XMLStatic.PRICEPROMGOOD);
        xmlSerializer.text(bean.getPricepromgood());
		xmlSerializer.endTag("", XMLStatic.PRICEPROMGOOD);
		xmlSerializer.startTag("", XMLStatic.OTHERPROMGOOD);
        xmlSerializer.text(bean.getOtherpromgood());
		xmlSerializer.endTag("", XMLStatic.OTHERPROMGOOD);
		xmlSerializer.startTag("", XMLStatic.TWOPOSDO);
        xmlSerializer.text(bean.getTwoposdo());
		xmlSerializer.endTag("", XMLStatic.TWOPOSDO);
		xmlSerializer.startTag("", XMLStatic.TWOPOSALL);
        xmlSerializer.text(null == bean.getTwoposall() ? "" : bean.getTwoposall());
		xmlSerializer.endTag("", XMLStatic.TWOPOSALL);
		xmlSerializer.startTag("", XMLStatic.POSM);
        xmlSerializer.text(null == bean.getPosm() ? "" : bean.getPosm());
		xmlSerializer.endTag("", XMLStatic.POSM);
		xmlSerializer.startTag("", XMLStatic.CRC);
        xmlSerializer.text(bean.getCrc());
		xmlSerializer.endTag("", XMLStatic.CRC);
		xmlSerializer.startTag("", XMLStatic.ORDERFORM);
        xmlSerializer.text(bean.getOrderform());
		xmlSerializer.endTag("", XMLStatic.ORDERFORM);
		xmlSerializer.startTag("", XMLStatic.KEEP);
        xmlSerializer.text(null == bean.getKeep() ? "" : bean.getKeep());
		xmlSerializer.endTag("", XMLStatic.KEEP);
		xmlSerializer.startTag("", XMLStatic.CUSER);
        xmlSerializer.text(bean.getCuser());
		xmlSerializer.endTag("", XMLStatic.CUSER);
		
		xmlSerializer.endTag("", XMLStatic.RECORDS);
		xmlSerializer.endTag("", XMLStatic.CONTENT);
		xmlSerializer.endDocument();
		writer.flush();
		writer.close();
		return writer.toString().replace("<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>", "");
	}
	
	public static List<CoopVisitBigShopInfoBean> parseXML(InputStream in) throws Exception {
        XmlPullParser parser = Xml.newPullParser();
        parser.setInput(in, "UTF-8");
        int type = parser.getEventType(); 
        
        CoopVisitBigShopInfoBean bean = null;
        List<CoopVisitBigShopInfoBean> list = null;
        
        while (type != XmlPullParser.END_DOCUMENT) { 
            switch (type) {   
            case XmlPullParser.START_DOCUMENT:   
            	list = new ArrayList<CoopVisitBigShopInfoBean>();   
                break;   
   
            case XmlPullParser.START_TAG:
                if ("Table".equals(parser.getName())) {
                	bean = new CoopVisitBigShopInfoBean();
                } else if (null != list && null != bean) {
                    if ("PARTNER".equals(parser.getName())) {   
                    	bean.setPartner(parser.nextText());   
                    } else if("VSDATE".equals(parser.getName())) {
                    	bean.setVsdate(parser.nextText());
                    } else if("CONTENT".equals(parser.getName())) {
                    	bean.setContent(parser.nextText());
                    } else if("AVGMONTHSALE".equals(parser.getName())) {
                    	bean.setAvgmonthsale(parser.nextText());
                    } else if("PREMONTHSALE".equals(parser.getName())) {
                    	bean.setPremonthsale(parser.nextText());
                    } else if("FIRSTCMPTSALE".equals(parser.getName())) {
                    	bean.setFirstcmptsale(parser.nextText());
                    } else if("PJPVISIT".equals(parser.getName())) {
                    	bean.setPjpvisit(parser.nextText());
                    } else if("ENTERTIME".equals(parser.getName())) {
                    	bean.setEntertime(parser.nextText());
                    } else if("LEAVETIME".equals(parser.getName())) {
                    	bean.setLeavetime(parser.nextText());
                    } else if("PREPARE".equals(parser.getName())) {
                    	bean.setPrepare(parser.nextText());
                    } else if("TALKLEVEL".equals(parser.getName())) {
                    	bean.setTalklevel(parser.nextText());
                    } else if("HANDLEVEL".equals(parser.getName())) {
                    	bean.setHandlevel(parser.nextText());
                    } else if("CUSER".equals(parser.getName())) {
                    	bean.setCuser(parser.nextText());
                    } else if("CDATE".equals(parser.getName())) {
                    	bean.setCdate(parser.nextText());
                    } else if("ISVISIT".equals(parser.getName())) {
                    	bean.setIsvisit(parser.nextText());
                    } else if("SHELFALL".equals(parser.getName())) {
                    	bean.setShelfall(parser.nextText());
                    } else if("SHELFSUB".equals(parser.getName())) {
                    	bean.setShelfsub(parser.nextText());
                    } else if("SHELFLEVEL".equals(parser.getName())) {
                    	bean.setShelflevel(parser.nextText());
                    } else if("CMULEVEL".equals(parser.getName())) {
                    	bean.setCmulevel(parser.nextText());
                    } else if("PRICEPROMGOOD".equals(parser.getName())) {
                    	bean.setPricepromgood(parser.nextText());
                    } else if("OTHERPROMGOOD".equals(parser.getName())) {
                    	bean.setOtherpromgood(parser.nextText());
                    } else if("TWOPOSDO".equals(parser.getName())) {
                    	bean.setTwoposdo(parser.nextText());
                    } else if("TWOPOSALL".equals(parser.getName())) {
                    	bean.setTwoposall(parser.nextText());
                    } else if("POSM".equals(parser.getName())) {
                    	bean.setPosm(parser.nextText());
                    } else if("CRC".equals(parser.getName())) {
                    	bean.setCrc(parser.nextText());
                    } else if("ORDERFORM".equals(parser.getName())) {
                    	bean.setOrderform(parser.nextText());
                    } else if("KEEP".equals(parser.getName())) {
                    	bean.setKeep(parser.nextText());
                    }
                }   
                break;   
   
            case XmlPullParser.END_TAG:   
                if ("Table".equals(parser.getName())) {
                	if (null != list && bean != null) {
                		list.add(bean);
                		bean = null;
                	} 
                }
                break;
            }
            type = parser.next();
        }   
        in.close();   
        return list;  
    }
}
